home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Inne / Gry / Carnage_Contest / scripts / CC Original / weapons / Machine Gun.lua < prev    next >
Text File  |  2010-09-02  |  6KB  |  169 lines

  1. --------------------------------------------------------------------------------
  2. -- Weapon Machine Gun + Projectile Bullet
  3. -- Original Carnage Contest Weapon
  4. -- Script by DC, August 2009, www.UnrealSoftware.de
  5. --------------------------------------------------------------------------------
  6.  
  7. -- Setup Tables
  8. if cc==nil then cc={} end
  9. cc.mg={}
  10. cc.mg.bullet={}
  11.  
  12. -- Load & Prepare Ressources
  13. cc.mg.gfx_wpn=loadgfx("weapons/mg.bmp")                        -- Weapon Image
  14. setmidhandle(cc.mg.gfx_wpn)
  15. cc.mg.gfx_pro=loadgfx("weapons/shot.bmp")                    -- Projectile Image
  16. setmidhandle(cc.mg.gfx_pro)
  17. cc.mg.sfx_attack=loadsfx("mg.wav")                            -- Attack Sound
  18.  
  19. --------------------------------------------------------------------------------
  20. -- Weapon: Machine Gun
  21. --------------------------------------------------------------------------------
  22.  
  23. cc.mg.id=addweapon("cc.mg","Machine Gun",cc.mg.gfx_wpn)        -- Add Weapon
  24. cc.mg.ammo=15                                                -- 15 Bullets
  25.  
  26. function cc.mg.draw()                                        -- Draw
  27.     setblend(blend_alpha)
  28.     setalpha(1)
  29.     setcolor(255,255,255)
  30.     drawinhand(cc.mg.gfx_wpn,6,0)
  31.     -- HUD ammobar
  32.     if cc.mg.ammo-weapon_shots>0 then
  33.         hudammobar(cc.mg.ammo-weapon_shots,cc.mg.ammo)
  34.     end
  35.     -- HUD Crosshair
  36.     if cc.mg.ammo-weapon_shots>0 then
  37.         hudcrosshair(7,3)
  38.     end
  39. end
  40.  
  41. function cc.mg.attack(attack)                                -- Attack
  42.     -- Decrement timer
  43.     if weapon_timer>0 then
  44.         weapon_timer=weapon_timer-1
  45.     end
  46.     -- Start burst
  47.     if attack==1 then
  48.         -- No more weapon switching!
  49.         useweapon(0)
  50.         weapon_mode=1
  51.     end
  52.     -- Attack
  53.     if weapon_shots<cc.mg.ammo and weapon_timer<=0 and weapon_mode==1 then
  54.         -- Reset Timer
  55.         weapon_timer=5
  56.         -- Attack
  57.         playsound(cc.mg.sfx_attack)
  58.         weapon_shots=weapon_shots+1
  59.         id=createprojectile(cc.mg.bullet.id)
  60.         projectiles[id]={}
  61.         -- Ignore collision with current player at beginning
  62.         projectiles[id].ignore=playercurrent()
  63.         -- Set initial position of projectile
  64.         projectiles[id].x=getplayerx(0)+(7*getplayerdirection(0))-math.sin(math.rad(getplayerrotation(0)))*5.0
  65.         projectiles[id].y=getplayery(0)+3+math.cos(math.rad(getplayerrotation(0)))*5.0
  66.         -- Set speed of projectile
  67.         projectiles[id].sx=math.sin(math.rad(getplayerrotation(0)))*15.0
  68.         projectiles[id].sy=-math.cos(math.rad(getplayerrotation(0)))*15.0
  69.         -- Initial movement
  70.         projectiles[id].x=projectiles[id].x-projectiles[id].sx*1.5
  71.         projectiles[id].y=projectiles[id].y-projectiles[id].sy*1.5
  72.         for i=1,3,1 do
  73.             if cc.mg.bullet.move(id)==1 then
  74.                 break
  75.             end
  76.         end
  77.         -- Effects
  78.         recoil(3)
  79.         particle(p_muzzle,getplayerx(0)+(getplayerdirection(0)*7)+math.sin(math.rad(getplayerrotation(0)))*16,getplayery(0)+3-math.cos(math.rad(getplayerrotation(0)))*16)
  80.         particle(p_smoke,getplayerx(0)+(getplayerdirection(0)*7)+math.sin(math.rad(getplayerrotation(0)))*16,getplayery(0)+3-math.cos(math.rad(getplayerrotation(0)))*16)
  81.         particlespeed(-0.2+math.random()*0.4+getwind()*10.0,-1.0+math.random()*0.6)
  82.         particlefadealpha(0.005)
  83.         particle(p_bullet,getplayerx(0)+(getplayerdirection(0)*3),getplayery(0)+3)
  84.         -- End Turn
  85.         if (weapon_shots>=cc.mg.ammo) then
  86.             endturn()
  87.         end
  88.     end
  89. end
  90.  
  91. --------------------------------------------------------------------------------
  92. -- Projectile: Bullet
  93. --------------------------------------------------------------------------------
  94.  
  95. cc.mg.bullet.id=addprojectile("cc.mg.bullet")            -- Add Projectile
  96.  
  97. function cc.mg.bullet.draw(id)                            -- Draw
  98.     -- Setup draw mode
  99.     setblend(blend_light)
  100.     setalpha(1)
  101.     setcolor(255,255,0)
  102.     setscale(1,1)
  103.     -- Calculate projectile rotation
  104.     setrotation(math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy)))
  105.     -- Draw projectile
  106.     drawimage(cc.mg.gfx_pro,projectiles[id].x,projectiles[id].y)
  107.     -- Draw Arrow if out of Screen
  108.     outofscreenarrow(projectiles[id].x,projectiles[id].y)
  109. end
  110.  
  111. function cc.mg.bullet.update(id)                        -- Update
  112.     -- Wind + Gravity influence on speed
  113.     projectiles[id].sx=projectiles[id].sx+getwind()*0.02
  114.     projectiles[id].sy=projectiles[id].sy+getgravity()*0.75
  115.     -- Move
  116.     cc.mg.bullet.move(id)
  117. end
  118.  
  119. function cc.mg.bullet.move(id)
  120.     rot=math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy))
  121.     -- Move (in substep loop for optimal collision precision)
  122.     msubt=math.ceil(math.max(math.abs(projectiles[id].sx),math.abs(projectiles[id].sy))/3)
  123.     msubx=projectiles[id].sx/msubt
  124.     msuby=projectiles[id].sy/msubt
  125.     for i=1,msubt,1 do
  126.         projectiles[id].x=projectiles[id].x+msubx
  127.         projectiles[id].y=projectiles[id].y+msuby        
  128.         -- Collision
  129.         if collision(col3x3,projectiles[id].x+math.sin(math.rad(rot))*20,projectiles[id].y-math.cos(math.rad(rot))*20)==1 then
  130.             if terraincollision()==1 or objectcollision()>0 or playercollision()~=projectiles[id].ignore then
  131.                 -- Cause damage
  132.                 if playercollision()~=0 and playercollision()~=projectiles[id].ignore then
  133.                     playerpush(playercollision(),projectiles[id].sx/10.0,projectiles[id].sy/10.0)
  134.                     playerdamage(playercollision(),2)
  135.                     blood(projectiles[id].x+math.sin(math.rad(rot))*20,projectiles[id].y-math.cos(math.rad(rot))*20)
  136.                 elseif objectcollision()>0 then
  137.                     objectdamage(objectcollision(),2)
  138.                 end
  139.                 -- Destroy terrain
  140.                 for j=20,22,1 do
  141.                     terraincircle(projectiles[id].x+math.sin(math.rad(rot))*j,projectiles[id].y-math.cos(math.rad(rot))*j,3,0x00000000)
  142.                 end
  143.                 -- Effects
  144.                 playsound(sfx_ricochet1)
  145.                 particle(p_smoke,projectiles[id].x+math.sin(math.rad(rot))*21,projectiles[id].y-math.cos(math.rad(rot))*21)
  146.                 particlefadealpha(0.006)
  147.                 particle(p_muzzle,projectiles[id].x+math.sin(math.rad(rot))*21,projectiles[id].y-math.cos(math.rad(rot))*21)
  148.                 -- Free projectile
  149.                 freeprojectile(id)
  150.                 return 1
  151.             end
  152.         else
  153.             projectiles[id].ignore=0
  154.         end
  155.         -- Water
  156.         if (projectiles[id].y)>getwatery()+5 then
  157.             -- Effects
  158.             particle(p_waterhit,projectiles[id].x,projectiles[id].y)
  159.             if math.random(1,2)==1 then
  160.                 playsound(sfx_hitwater2)
  161.             else
  162.                 playsound(sfx_hitwater3)
  163.             end
  164.             -- Free projectile
  165.             freeprojectile(id)
  166.             return 1
  167.         end
  168.     end
  169. end